package component;

import com.google.gson.annotations.Expose;
import util.common.JsonUtil;
import model.MibNode;

public class NodePersistenceComponent {
    @Expose
    public String type;
    @Expose
    public String json;

    public static String toJson(MibNode node){
        NodePersistenceComponent bean = new NodePersistenceComponent();
        bean.type = node.clazzName;
        bean.json = JsonUtil.toJson(node);
        return JsonUtil.toJson(bean);
    }

    public static MibNode fromJson(String str) throws ClassNotFoundException {
        NodePersistenceComponent bean = (NodePersistenceComponent) JsonUtil.fromJson(str, NodePersistenceComponent.class);
        MibNode node = (MibNode) JsonUtil.fromJson(bean.json, Class.forName(bean.type));
        return node;
    }
}
